package com.imooc.coupon.controller;

import com.alibaba.fastjson.JSON;
import com.imooc.coupon.exception.CouponException;
import com.imooc.coupon.executor.ExecuteManager;
import com.imooc.coupon.vo.SettlementInfo; 
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

//结算服务 Controller
@Slf4j
@RestController
public class SettlementController {
    //结算规则执行管理器
    private ExecuteManager executeManager;

    @Autowired
    public SettlementController(ExecuteManager executeManager) {
        this.executeManager = executeManager;
    }

    @PostMapping("/settlement/compute")
    public SettlementInfo computeRule(SettlementInfo settlement)
            throws CouponException{
        log.info("settlement：{}", JSON.toJSONString(settlement));
        return executeManager.computeRule(settlement);
    }
}
